package com.chen.facemanager.dao;

import com.chen.facemanager.bean.User;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserDao extends CrudRepository<User,Long> {

    User findByPhoneAndPassword(String phone,String password);

    @Query(value = "update User u set u.name = ?2,u.idNumber = ?3,u.address = ?4,u.sex = ?5,u.photo = ?6,u.status = 1,u.birthday = ?7 where u.id = ?1")
    @Modifying
    int updateUser(Long id,String name,String idNumber,String address,String sex,String photo,String birthday);

    @Query("update User u set u.phone = ?2 where u.id = ?1")
    @Modifying
    int updatePhone(Long id,String phone);

    @Query("update User u set u.password = ?2 where u.id = ?1")
    @Modifying
    int updatePwd(Long id,String password);

    User findByIdAndPassword(Long id,String pwd);

    @Query("update User u set u.password = ?2 where u.phone = ?1")
    @Modifying
    int resetPwd(String phone, String password);

    List<User> findUsersByPhone(String phone);
}
